export default {
	state: {
		loginStatus: true,
		token: null,
		userInfo: {}
	},
	getters: {},
	mutations: {
		// 一旦进入app，就拿出信息
		initUser(state) {
			let userInfo = uni.getStorageSync('userInfo')
			if (userInfo) {
				userInfo = JSON.parse(userInfo)
				state.userInfo = userInfo;
				console.log(true, 'true');
				state.token = userInfo.token;
			}
		},
		// 登录保存用户信息
		login(state, userInfo) {
			state.userInfo = userInfo;
			state.loginStatus = true;
			state.token = userInfo.token;
			// 持久化存储
			uni.setStorageSync('userInfo', JSON.stringify(userInfo))
		},
		// 退出登录
		loginOut(state) {
			state.userInfo = {};
			state.loginStatus = false;
			state.token = null;
			uni.removeStorageSync('userInfo')
		}
	}
}
